package com.example.mapper;

import com.example.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @auth shanyue
 * @date 2025年06月06日14:05
 */
@Mapper
public interface UserMapper {

    @Results({
            @Result(column = "create_time", property = "createTime")
    })
    @Select("SELECT * FROM users WHERE username = #{username}")
    User findByUsername(String username);

    @Results({
            @Result(column = "create_time", property = "createTime")
    })
    @Select("SELECT * FROM users")
    List<User> findAll();

    @Insert("INSERT INTO users(username,password,role,create_time) VALUES(#{username},#{password},#{role},#{createTime})")
    int insert(User user);

    @Select("select * from users where id = #{id}")
    User getUserById(Integer id);

    @Update("UPDATE users SET username=#{username},password=#{password},role=#{role} WHERE id=#{id}")
    void update(User user);

    @Delete("DELETE FROM users WHERE id=#{id}")
    void delete(Integer id);
}
